package com.briup.day08;

import sun.security.util.Length;

import java.util.Arrays;

/**
 * @author ThinkBook
 */
public class Test03_Copy {
//    拷贝数组，扩容两倍
    public static int[] extend(int[] src){
        //先准备一个空白数组，容量为src的两倍
        int[] dest = new int[src.length * 2];
        //拷贝
        System.arraycopy(src,0,dest,0,src.length);
        //返回
        return dest;
    }

    public static void main(String[] args) {
        int[] array = {1,2,3,4,5};
        int[] newArr = extend(array);
        System.out.println(Arrays.toString(newArr));
        // [1, 2, 3, 4, 5, 0, 0, 0, 0, 0]
        //将array 拷贝到 newArr的最后面5个元素位置
        System.arraycopy(array,0,newArr,5,array.length);
        System.out.println(Arrays.toString(newArr));
    }
}
